

package TransportesMarroquin;

import com.mysql.jdbc.Connection;

import java.awt.event.ActionEvent; 
import java.awt.event.KeyEvent; 
import javax.sound.sampled.Clip; 
import javax.swing.JButton; 
import javax.swing.JFrame; 
import javax.swing.JLabel; 
import javax.swing.JPanel; 
import javax.swing.JTextField;
import com.mysql.jdbc.PreparedStatement;
import com.mysql.jdbc.Statement;
import com.mysql.jdbc.jdbc2.optional.MysqlDataSource;
import java.awt.Color;
import java.awt.Toolkit;
import java.io.File;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.sound.sampled.AudioSystem;
import javax.swing.JOptionPane;


public class LlantasCabezal extends javax.swing.JFrame {
javax.sound.sampled.Clip sonido;
   int num[]= new int[10];
   
   int resultado;
   int codpaquete;
   boolean error = false;
   boolean completo = false;
   int codcab=0;
   Limitador limdd = new Limitador(11);
   Limitador limdi = new Limitador(11);
   Limitador limmed = new Limitador(11);
   Limitador limmei = new Limitador(11);
   Limitador limdii = new Limitador(11);
   Limitador limdil = new Limitador(11);
   Limitador limted = new Limitador(11);
   Limitador limtei = new Limitador(11);
   Limitador limtid = new Limitador(11);
   Limitador limtii = new Limitador(11);

    public LlantasCabezal() {
        
    }
      
    public LlantasCabezal(int cod){
        this.codcab=cod;
        initComponents();
    dd.setDocument(limdd);
    di.setDocument(limdi);
    med.setDocument(limmed);
    mei.setDocument(limmei);
    mii.setDocument(limdii);
    mil.setDocument(limdil);
    ted.setDocument(limted);
    tei.setDocument(limtei);
    tid.setDocument(limtid);
    tii.setDocument(limtii);
    }
    
 
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        jLabel7 = new javax.swing.JLabel();
        jLabel8 = new javax.swing.JLabel();
        jLabel10 = new javax.swing.JLabel();
        jLabel11 = new javax.swing.JLabel();
        jLabel12 = new javax.swing.JLabel();
        jLabel14 = new javax.swing.JLabel();
        dd = new javax.swing.JTextField();
        di = new javax.swing.JTextField();
        mei = new javax.swing.JTextField();
        mii = new javax.swing.JTextField();
        mil = new javax.swing.JTextField();
        med = new javax.swing.JTextField();
        tei = new javax.swing.JTextField();
        tii = new javax.swing.JTextField();
        tid = new javax.swing.JTextField();
        ted = new javax.swing.JTextField();
        jButton1 = new javax.swing.JButton();
        jButton3 = new javax.swing.JButton();
        jButton2 = new javax.swing.JButton();
        jPanel1 = new javax.swing.JPanel();
        jLabel13 = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("Nuevo Paquete Llantas Cabezal ");

        jLabel3.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Imagenes/ImagenLlanta.png"))); // NOI18N

        jLabel4.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Imagenes/ImagenLlanta.png"))); // NOI18N

        jLabel5.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Imagenes/ImagenLlanta.png"))); // NOI18N

        jLabel6.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Imagenes/ImagenLlanta.png"))); // NOI18N

        jLabel7.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Imagenes/ImagenLlanta.png"))); // NOI18N

        jLabel8.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Imagenes/ImagenLlanta.png"))); // NOI18N

        jLabel10.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Imagenes/ImagenLlanta.png"))); // NOI18N

        jLabel11.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Imagenes/ImagenLlanta.png"))); // NOI18N

        jLabel12.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Imagenes/ImagenLlanta.png"))); // NOI18N

        jLabel14.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Imagenes/ImagenLlanta.png"))); // NOI18N

        dd.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                ddKeyTyped(evt);
            }
        });

        di.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                diKeyTyped(evt);
            }
        });

        mei.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                meiKeyTyped(evt);
            }
        });

        mii.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                miiKeyTyped(evt);
            }
        });

        mil.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                milActionPerformed(evt);
            }
        });
        mil.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                milKeyTyped(evt);
            }
        });

        med.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                medKeyTyped(evt);
            }
        });

        tei.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                teiKeyTyped(evt);
            }
        });

        tii.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                tiiKeyTyped(evt);
            }
        });

        tid.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                tidKeyTyped(evt);
            }
        });

        ted.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                tedKeyTyped(evt);
            }
        });

        jButton1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Imagenes/aceptar.png"))); // NOI18N
        jButton1.setText("Ingresar");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        jButton3.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Imagenes/cancelar.png"))); // NOI18N
        jButton3.setText("Cancerlar");
        jButton3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton3ActionPerformed(evt);
            }
        });

        jButton2.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Imagenes/regresar.png"))); // NOI18N
        jButton2.setText("Regresar");
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });

        jPanel1.setBackground(new java.awt.Color(143, 0, 0));

        jLabel13.setFont(new java.awt.Font("Tahoma", 1, 18));
        jLabel13.setForeground(new java.awt.Color(255, 255, 255));
        jLabel13.setText("Nuevo Cabezal                                             - LLantas -");

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel13)
                .addContainerGap(14, Short.MAX_VALUE))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel13)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(19, 19, 19)
                .addComponent(di, javax.swing.GroupLayout.PREFERRED_SIZE, 34, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(10, 10, 10)
                .addComponent(jLabel3)
                .addGap(310, 310, 310)
                .addComponent(jLabel8)
                .addGap(13, 13, 13)
                .addComponent(dd, javax.swing.GroupLayout.PREFERRED_SIZE, 41, javax.swing.GroupLayout.PREFERRED_SIZE))
            .addGroup(layout.createSequentialGroup()
                .addGap(19, 19, 19)
                .addComponent(mei, javax.swing.GroupLayout.PREFERRED_SIZE, 37, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(10, 10, 10)
                .addComponent(jLabel5)
                .addGap(18, 18, 18)
                .addComponent(jLabel7)
                .addGap(4, 4, 4)
                .addComponent(mii, javax.swing.GroupLayout.PREFERRED_SIZE, 38, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(140, 140, 140)
                .addComponent(mil, javax.swing.GroupLayout.PREFERRED_SIZE, 46, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(14, 14, 14)
                .addComponent(jLabel4)
                .addGap(13, 13, 13)
                .addComponent(jLabel6)
                .addGap(13, 13, 13)
                .addComponent(med, javax.swing.GroupLayout.PREFERRED_SIZE, 41, javax.swing.GroupLayout.PREFERRED_SIZE))
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addGap(10, 10, 10)
                .addComponent(jButton2)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 127, Short.MAX_VALUE)
                .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 113, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jButton3, javax.swing.GroupLayout.PREFERRED_SIZE, 113, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(8, 8, 8))
            .addGroup(layout.createSequentialGroup()
                .addGap(19, 19, 19)
                .addComponent(tei, javax.swing.GroupLayout.PREFERRED_SIZE, 37, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(10, 10, 10)
                .addComponent(jLabel11)
                .addGap(18, 18, 18)
                .addComponent(jLabel14)
                .addGap(4, 4, 4)
                .addComponent(tii, javax.swing.GroupLayout.PREFERRED_SIZE, 38, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(140, 140, 140)
                .addComponent(tid, javax.swing.GroupLayout.PREFERRED_SIZE, 46, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(14, 14, 14)
                .addComponent(jLabel10)
                .addGap(13, 13, 13)
                .addComponent(jLabel12)
                .addGap(13, 13, 13)
                .addComponent(ted, javax.swing.GroupLayout.PREFERRED_SIZE, 41, javax.swing.GroupLayout.PREFERRED_SIZE))
            .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(24, 24, 24)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(30, 30, 30)
                        .addComponent(di, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(jLabel3)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(2, 2, 2)
                        .addComponent(jLabel8))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(32, 32, 32)
                        .addComponent(dd, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addGap(110, 110, 110)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(31, 31, 31)
                        .addComponent(mei, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(1, 1, 1)
                        .addComponent(jLabel5))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(1, 1, 1)
                        .addComponent(jLabel7))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(31, 31, 31)
                        .addComponent(mii, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(30, 30, 30)
                        .addComponent(mil, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(jLabel4)
                    .addComponent(jLabel6)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(30, 30, 30)
                        .addComponent(med, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(30, 30, 30)
                        .addComponent(tei, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(jLabel11)
                    .addComponent(jLabel14)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(30, 30, 30)
                        .addComponent(tii, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(31, 31, 31)
                        .addComponent(tid, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(1, 1, 1)
                        .addComponent(jLabel10))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(1, 1, 1)
                        .addComponent(jLabel12))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(31, 31, 31)
                        .addComponent(ted, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addGap(48, 48, 48)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 26, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jButton3, javax.swing.GroupLayout.PREFERRED_SIZE, 26, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(jButton2, javax.swing.GroupLayout.PREFERRED_SIZE, 26, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed
        dispose();
        Cabezal.nc.dispose();
        Error.Mysql("delete from cabezal where idcabezal="+codcab);
        Cabezal va;
       
            va = new Cabezal();
            va.setVisible(true);
             va.setBounds(114, 107, Toolkit.getDefaultToolkit().getScreenSize().width-114, Toolkit.getDefaultToolkit().getScreenSize().height-107);
        
     
     
}//GEN-LAST:event_jButton3ActionPerformed

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
error = false ; // inicialiso como qee no hay error.           
           IngresarLlantas();
          if(error==false){
               LlenarPacketeN();
          } 
          
           if(completo==true){
                // oculto la llantas furgon

            IngresarPaqueteACabezal();
            Cabezal.nc.dispose();
            dispose();
            Cabezal va;
       
            va = new Cabezal();
            va.setVisible(true);
             va.setBounds(114, 107, Toolkit.getDefaultToolkit().getScreenSize().width-114, Toolkit.getDefaultToolkit().getScreenSize().height-107);
        
      
}


    }//GEN-LAST:event_jButton1ActionPerformed

    private void milActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_milActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_milActionPerformed

    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
      NuevoCabezal.va.dispose();
      Cabezal.nc.show();
      Error.Mysql("DELETE from cabezal where idcabezal = "+NuevoCabezal.cod);
    }//GEN-LAST:event_jButton2ActionPerformed

    private void diKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_diKeyTyped
         char c = evt.getKeyChar();
       if(!(Character.isDigit(c))|| c== evt.VK_BACK_SPACE || c==evt.VK_DELETE){
           getToolkit().beep();
           evt.consume();
       }
    }//GEN-LAST:event_diKeyTyped

    private void meiKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_meiKeyTyped
        char c = evt.getKeyChar();
       if(!(Character.isDigit(c))|| c== evt.VK_BACK_SPACE || c==evt.VK_DELETE){
           getToolkit().beep();
           evt.consume();
       }
    }//GEN-LAST:event_meiKeyTyped

    private void teiKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_teiKeyTyped
        char c = evt.getKeyChar();
       if(!(Character.isDigit(c))|| c== evt.VK_BACK_SPACE || c==evt.VK_DELETE){
           getToolkit().beep();
           evt.consume();
       }
    }//GEN-LAST:event_teiKeyTyped

    private void miiKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_miiKeyTyped
         char c = evt.getKeyChar();
       if(!(Character.isDigit(c))|| c== evt.VK_BACK_SPACE || c==evt.VK_DELETE){
           getToolkit().beep();
           evt.consume();
       }
    }//GEN-LAST:event_miiKeyTyped

    private void tiiKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_tiiKeyTyped
        char c = evt.getKeyChar();
       if(!(Character.isDigit(c))|| c== evt.VK_BACK_SPACE || c==evt.VK_DELETE){
           getToolkit().beep();
           evt.consume();
       }
    }//GEN-LAST:event_tiiKeyTyped

    private void milKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_milKeyTyped
         char c = evt.getKeyChar();
       if(!(Character.isDigit(c))|| c== evt.VK_BACK_SPACE || c==evt.VK_DELETE){
           getToolkit().beep();
           evt.consume();
       }
    }//GEN-LAST:event_milKeyTyped

    private void tidKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_tidKeyTyped
         char c = evt.getKeyChar();
       if(!(Character.isDigit(c))|| c== evt.VK_BACK_SPACE || c==evt.VK_DELETE){
           getToolkit().beep();
           evt.consume();
       }
    }//GEN-LAST:event_tidKeyTyped

    private void ddKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_ddKeyTyped
         char c = evt.getKeyChar();
       if(!(Character.isDigit(c))|| c== evt.VK_BACK_SPACE || c==evt.VK_DELETE){
           getToolkit().beep();
           evt.consume();
       }
    }//GEN-LAST:event_ddKeyTyped

    private void medKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_medKeyTyped
         char c = evt.getKeyChar();
       if(!(Character.isDigit(c))|| c== evt.VK_BACK_SPACE || c==evt.VK_DELETE){
           getToolkit().beep();
           evt.consume();
       }
    }//GEN-LAST:event_medKeyTyped

    private void tedKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_tedKeyTyped
        char c = evt.getKeyChar();
       if(!(Character.isDigit(c))|| c== evt.VK_BACK_SPACE || c==evt.VK_DELETE){
           getToolkit().beep();
           evt.consume();
       }
    }//GEN-LAST:event_tedKeyTyped

   public void IngresarLlantas (){

     try {
          

            resultado = 0 ;

          

            MysqlDataSource dataSource = new MysqlDataSource();
            dataSource.setUser("root");
            dataSource.setPassword("");
            dataSource.setDatabaseName("practicasp8");
            dataSource.setServerName("localhost");
          Connection  conexion = (Connection) dataSource.getConnection();

            Statement instruccion;
            ResultSet rs;
            instruccion = (Statement) conexion.createStatement();
                  
 // LLANTA UNO
            try {
                     num[0]=Integer.parseInt(di.getText());
                }catch (Exception e){
                    JOptionPane.showMessageDialog(rootPane, "Dato erroneo en la llanta delantera izquierda, no és un valor númerico  ");

                }
            
              if(error==false){
            try{
                 instruccion.executeUpdate("insert into llanta (idnumeconomico,tipo_vehiculo,codigo_vehiculo,posicion) values('" + num[0] + "','Cabezal','"+codcab+"','Llanta delantera izquierda ')",Statement.RETURN_GENERATED_KEYS); // me sirve para obter el id de llanta uno
            }catch (Exception e ){
                error=true;
                GeneracionError();
                di.setText(""+"Error");
                di.setBackground(Color.red);
                JOptionPane.showMessageDialog(rootPane, "Dato erroneo en la llanta delantera izquierda''"+num[0] +"'' número economico ya existente"+e);
            }
          
            }
                   
        




// LLANTA DOS
    try {
                     num[1]=Integer.parseInt(dd.getText());
                }catch (Exception e){
                    JOptionPane.showMessageDialog(rootPane, "Dato erroneo en la llanta delantera derecha, no és un valor númerico ");

                }
    // este try borra todos los datos anteriormente ya ingresados para evitar errore
                 // asi como tambien para que el usuario localice el error
             if(error==false){    // este if verifica continuidad del error si hay error anteriormente no ingresa nada :D
                 try{
                instruccion.executeUpdate("insert into llanta (idnumeconomico,tipo_vehiculo,codigo_vehiculo,posicion) values ('" + num[1] + "','Cabezal','"+codcab+"','Llanta delantera derecha ')",Statement.RETURN_GENERATED_KEYS);
                 }catch (Exception e ){
                error=true;
                GeneracionError();
                dd.setText(""+"Error");
                dd.setBackground(Color.red);
                JOptionPane.showMessageDialog(rootPane, "Dato erroneo en la llanta delantera izquierda interna ''"+num[1] +"'' número economico ya existente");
            }
           
            }


//LLANTA TRES
           
           try {
                     num[2]=Integer.parseInt(mei.getText());
                }catch (Exception e){
                    JOptionPane.showMessageDialog(rootPane, "Dato erroneo en la llanta de en medio externa izquiera  ");

                }

       // este try borra todos los datos anteriormente ya ingresados para evitar errore
                 // asi como tambien para que el usuario localice el error
             if(error==false){    // este if verifica continuidad del error si hay error anteriormente no ingresa nada :D
                 try{
                instruccion.executeUpdate("insert into llanta (idnumeconomico,tipo_vehiculo,codigo_vehiculo,posicion) values ('" + num[2] + "','Cabezal','"+codcab+"','Llanta de en medio externa izquierda ')",Statement.RETURN_GENERATED_KEYS);
                 }catch (Exception e ){
                error=true;
                GeneracionError();
                mei.setText(""+"Error");
                mei.setBackground(Color.red);
                JOptionPane.showMessageDialog(rootPane, "Dato erroneo en la llanta de en medio externa izquierda  ''"+num[2] +"'' número economico ya existente");
            }
           
            }



// LLANTA CUATRO
             try {
                     num[3]=Integer.parseInt(mii.getText());
                }catch (Exception e){
                    JOptionPane.showMessageDialog(rootPane, "Dato erroneoen la llanta de en medio interna izquierda, no és un valor númerico  ");

                }
            try{
                instruccion.executeUpdate("insert into llanta (idnumeconomico,tipo_vehiculo,codigo_vehiculo,posicion) values ('" + num[3] + "','Cabezal','"+codcab+"','Llanta de en medio interna izquierda')",Statement.RETURN_GENERATED_KEYS);
                 }catch (Exception e ){
                error=true;
                GeneracionError();
                mii.setText(""+"Error");
                mii.setBackground(Color.red);
                JOptionPane.showMessageDialog(rootPane, "Dato erroneo en la llanta de en medio interna izquierda''"+num[3] +"'' número economico ya existente");
            }


  //LLANTA CINCO
              try {
                     num[4]=Integer.parseInt(mil.getText());
                }catch (Exception e){
                    JOptionPane.showMessageDialog(rootPane, "Dato erroneo en la llanta de en medio izquierda lateral, no és un dato númerico  ");

                }
            try{
                instruccion.executeUpdate("insert into llanta (idnumeconomico,tipo_vehiculo,codigo_vehiculo,posicion) values ('" + num[4] + "','Cabezal','"+codcab+"','Llanta trasera izquierda externa')",Statement.RETURN_GENERATED_KEYS);
                 }catch (Exception e ){
                error=true;
                GeneracionError();
                mil.setText(""+"Error");
                mil.setBackground(Color.red);
                JOptionPane.showMessageDialog(rootPane, "Dato erroneo en la llanta trasera izquierda externa ''"+num[4] +"'' número economico ya existente");
            }
            
//LANTA SEIS
               try {
                     num[5]=Integer.parseInt(med.getText());
                }catch (Exception e){
                    JOptionPane.showMessageDialog(rootPane, "Dato erroneo en la llanta de en medio externa derecho, no és un dato númerico");

                }
         try{
                instruccion.executeUpdate("insert into llanta (idnumeconomico,tipo_vehiculo,codigo_vehiculo,posicion) values ('" + num[5] + "','Cabezal','"+codcab+"','Llanta de en medio externa derecha')",Statement.RETURN_GENERATED_KEYS);
                 }catch (Exception e ){
                error=true;
                GeneracionError();
                med.setText(""+"Error");
                med.setBackground(Color.red);
                JOptionPane.showMessageDialog(rootPane, "Dato erroneo en la llanta de en medio externa derecha''"+num[5] +"'' número economico ya existente");
            }
                

 //LLNATA SIETE
             try {
                     num[6]=Integer.parseInt(tei.getText());
                }catch (Exception e){
                    JOptionPane.showMessageDialog(rootPane, "Dato erroneo en la llanta trasera externa izquierda, no es un dato númerico  ");

                }

           try{
                instruccion.executeUpdate("insert into llanta (idnumeconomico,tipo_vehiculo,codigo_vehiculo,posicion) values ('" + num[6] + "','Cabezal','"+codcab+"','Llanta trasera externa izquierda')",Statement.RETURN_GENERATED_KEYS);
                 }catch (Exception e ){
                error=true;
                GeneracionError();
                tei.setText(""+"Error");
                tei.setBackground(Color.red);
                JOptionPane.showMessageDialog(rootPane, "Dato erroneo en la llanta trasera externa izquierda ''"+num[6] +"'' número economico ya existente");
          
                 
                 }
     

                

 //LLANTA OCHO
               try {
                     num[7]=Integer.parseInt(tii.getText());
                }catch (Exception e){
                    JOptionPane.showMessageDialog(rootPane, "Dato erroneo en la llanta trasera interna izquierda  ");


                }
  try{
                instruccion.executeUpdate("insert into llanta (idnumeconomico,tipo_vehiculo,codigo_vehiculo,posicion) values ('" + num[7] + "','Cabezal','"+codcab+"','Llanta trasera interna izquierda')",Statement.RETURN_GENERATED_KEYS);
                
                      
           }catch (Exception e ){
                error=true;
                GeneracionError();
                tii.setText(""+"Error");
                tii.setBackground(Color.red);
                JOptionPane.showMessageDialog(rootPane, "Dato erroneo en la llanta trasera interna izquierda ''"+num[7] +"'' número economico ya existente");
            }

                
//LLANTA NUEVE
                try {
                     num[8]=Integer.parseInt(tid.getText());
                }catch (Exception e){
                    JOptionPane.showMessageDialog(rootPane, "Dato erroneo trasera interna derecha, no es un dato númerico  ");

                }
        try{
                instruccion.executeUpdate("insert into llanta (idnumeconomico,tipo_vehiculo,codigo_vehiculo,posicion) values ('" + num[8] + "','Cabezal','"+codcab+"','Llanta trasera interna derecha')",Statement.RETURN_GENERATED_KEYS);
                
                      
           }catch (Exception e ){
                error=true;
                GeneracionError();
                tid.setText(""+"Error");
                tid.setBackground(Color.red);
                JOptionPane.showMessageDialog(rootPane, "Dato erroneo en la llanta trasera interna derecha ''"+num[8] +"'' número economico ya existente");
            }
 //LLANTA DIEZ
             try {
                     num[9]=Integer.parseInt(ted.getText());
                }catch (Exception e){
                    JOptionPane.showMessageDialog(rootPane, "Dato erroneo en la llanta trasera externa derecha, no es un data númerico");

                }
  try{
                instruccion.executeUpdate("insert into llanta (idnumeconomico,tipo_vehiculo,codigo_vehiculo,posicion) values ('" + num[9] + "','Cabezal','"+codcab+"','Llanta trasera externa derecha')",Statement.RETURN_GENERATED_KEYS);
                
                      
           }catch (Exception e ){
                error=true;
                GeneracionError();
                ted.setText(""+"Error");
                ted.setBackground(Color.red);
                JOptionPane.showMessageDialog(rootPane, "Dato erroneo en la llanta trasera externa derecha''"+num[9] +"'' número economico ya existente");
            }

            // sonido

     if (error==false){
            try
                {
                  sonido = null;
                  sonido=AudioSystem.getClip();
                  sonido.open(AudioSystem.getAudioInputStream(new File(System.getProperty ("user.dir")+"\\src\\SonidosPractica\\Correcto2.wav")));
                  sonido.start();




                }catch(Exception e)
                  {System.out.println(""+e);} // fin


                            JOptionPane.showMessageDialog(rootPane, "Dato ingresado exitosamente"+resultado);
     }


               conexion.close(); // cierro la conexion
               

             }catch(SQLException e){
            
           JOptionPane.showMessageDialog(rootPane,"Error en la base de Datos :"+e.toString());
           error = true;
           GeneracionError();
           } // fin del catch

   }

  
  public void  IngresarPaqueteACabezal (){
        try {
            MysqlDataSource dataSource = new MysqlDataSource();
               dataSource.setUser("root");
               dataSource.setPassword("");
               dataSource.setDatabaseName("practicasp8");
               dataSource.setServerName("localhost");
               Connection conexion = (Connection) dataSource.getConnection();
               Statement instruccion;
               
               instruccion=(Statement) conexion.createStatement();
               instruccion.executeUpdate("update cabezal set idpaquetecabezal='"+ codpaquete+"' where idcabezal="+codcab);
        } catch (SQLException ex) {
            Logger.getLogger(LlantasFurgon.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
   public void LlenarPacketeN (){
       {

     try {
            resultado = 0 ;

            MysqlDataSource dataSource = new MysqlDataSource();
            dataSource.setUser("root");
            dataSource.setPassword("");
            dataSource.setDatabaseName("practicasp8");
            dataSource.setServerName("localhost");
             // coneccion
            Connection conexion = (Connection) dataSource.getConnection();
            ResultSet rs;
            PreparedStatement ps = null;

            ps = (PreparedStatement) conexion.prepareStatement("insert into paquetecabezal (di,dd,mei,mii,mil,med,tei,tii,tid,ted) values (?,?,?,?,?,?,?,?,?,?)");

            try {
                 ps.setInt(1,num[0]);
            }catch(Exception e){
                   JOptionPane.showMessageDialog(rootPane, "Dato erroneo Revisar Manual  ");

           } // fin del catch

  // LLANTA DOS
           
          

            try {
                 ps.setInt(2,num[1]);
            }catch(Exception e){
                   JOptionPane.showMessageDialog(rootPane, "Dato erroneo Revisar Manual  ");

           } // fin del catch

//LANTA TRES
         
            try {
                 ps.setInt(3,num[2]);
            }catch(Exception e){
                   JOptionPane.showMessageDialog(rootPane, "Dato erroneo Revisar Manual  ");

           } // fin del catch
 // LLANTA CUATRO
          

            try {
                 ps.setInt(4,num[3]);
            }catch(Exception e){
                   JOptionPane.showMessageDialog(rootPane, "Dato erroneo Revisar Manual  ");

           } // fin del catch
 //LLANTA CINCO
           
            try {
                 ps.setInt(5,num[4]);
            }catch(Exception e){
                   JOptionPane.showMessageDialog(rootPane, "Dato erroneo Revisar Manual  ");

           } // fin del catch
 //LANTA SEIS
          

            try {
                 ps.setInt(6,num[5]);
            }catch(Exception e){
                   JOptionPane.showMessageDialog(rootPane, "Dato erroneo Revisar Manual  ");

           } // fin del catch
   //LLNATA SIETE
           

            try {
               ps.setInt(7,num[6]);
            }catch(Exception e){
                   JOptionPane.showMessageDialog(rootPane, "Dato erroneo Revisar Manual  ");

           } // fin del catch
 //LLANTA OCHO
           

            try {
                 ps.setInt(8,num[7]);
            }catch(Exception e){
                   JOptionPane.showMessageDialog(rootPane, "Dato erroneo Revisar Manual  ");

           } // fin del catch
   //LLANTA NUEVE
           
            try {
                 ps.setInt(9,num[8]);
            }catch(Exception e){
                   JOptionPane.showMessageDialog(rootPane, "Dato erroneo Revisar Manual  ");

           } // fin del catch
  //LLANTA DIEZ
          

            try {
                 ps.setInt(10,num[9]);
            }catch(Exception e){
                   JOptionPane.showMessageDialog(rootPane, "Dato erroneo Revisar Manual  ");

           } // fin del catch

             resultado = ps.executeUpdate();
           
               rs = ps.getGeneratedKeys();
            while (rs.next()) {
                codpaquete = rs.getInt(1);
                
                }


            JOptionPane.showMessageDialog(rootPane, "Dato ingresado exitosamente");
           
               conexion.close(); // cierro la conexion
               ps.close();

             }catch(SQLException e){

            System.out.println("EXCEPCION EN Base de Datos:"+e.toString());
           } // fin del catch
    completo =true;
   }

   }
    public void GeneracionError (){
        try {
            MysqlDataSource dataSource = new MysqlDataSource();
            dataSource.setUser("root");
            dataSource.setPassword("");
            dataSource.setDatabaseName("practicasp8");
            dataSource.setServerName("localhost");
            Connection conexion = (Connection) dataSource.getConnection();
            Statement instruccion;

            instruccion = (Statement) conexion.createStatement();
            for(int i=0; i!=8;i++){
               instruccion.executeUpdate("DELETE from llanta where idnumeconomico = "+num[i]+" AND codigo_vehiculo ="+codcab+" AND tipo_vehiculo LIKE 'Cabezal'");
               
            }
            conexion.close();
            instruccion.close();
        } catch (SQLException ex) {
            Logger.getLogger(LlantasFurgon.class.getName()).log(Level.SEVERE, null, ex);
           
        }
  }
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new LlantasCabezal().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JTextField dd;
    private javax.swing.JTextField di;
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JButton jButton3;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel13;
    private javax.swing.JLabel jLabel14;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JTextField med;
    private javax.swing.JTextField mei;
    private javax.swing.JTextField mii;
    private javax.swing.JTextField mil;
    private javax.swing.JTextField ted;
    private javax.swing.JTextField tei;
    private javax.swing.JTextField tid;
    private javax.swing.JTextField tii;
    // End of variables declaration//GEN-END:variables

}
